/*
 *  Copyright (C) 2010 Fabien Renaud
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.boc.botv.service.impl;

import com.boc.botv.dao.TransactionDao;
import com.boc.botv.model.SiteAccount;
import com.boc.botv.model.Transaction;
import com.boc.botv.model.User;
import com.boc.botv.service.TransactionManager;
import java.util.Date;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 * @author Fabien Renaud
 */
@Service("transactionManager")
//@Transactional(readOnly = true)
public class TransactionManagerImpl implements TransactionManager {

  private final Log logger = LogFactory.getLog(TransactionManagerImpl.class);
  private TransactionDao transactionDao;

  @Autowired
  public void setTransactionDao(TransactionDao transactionDao) {
    this.transactionDao = transactionDao;
  }

  public List<Transaction> getTransactions() {
    logger.info("[TransactionManager] Getting transactions");
    return transactionDao.getTransactions();
  }

  public List<Transaction> getTransactions(User user) {
    logger.info("[TransactionManager] Getting transactions for user `" + user.getLogin() + "`");
    return transactionDao.getTransactionsUser(user.getId());
  }

  public List<Transaction> getTransactions(SiteAccount siteAccount) {
    logger.info("[TransactionManager] Getting transactions for site account #" + siteAccount.getId());
    return transactionDao.getTransactionsSite(siteAccount.getId());
  }

  public List<Transaction> getTransactionsBetween(Date firstDate, Date lastDate) {
    logger.info("[TransactionManager] Getting transactions between " + firstDate + " and " + lastDate);
    return transactionDao.getTransactionsBetween(firstDate, lastDate);
  }

  //@Transactional(readOnly = false)
  public void createTransaction(Transaction transaction) {
    logger.info("[TransactionManager] Creating transactions");
    transactionDao.saveTransaction(transaction);
  }
}
